﻿@model GPI.Models.GPI_PROJECT

@{
    ViewBag.Title = "Détails";
    bool open = ViewBag.open; // Release : bool open = ViewBag.open;
    bool prof = ViewBag.prof;
    bool creator = User.Identity.Name.Equals(Model.FK_Prof);
    bool subscribed = ViewBag.subscribed;
}

@if (ViewBag.maxReached)
{ 
    <script type="text/javascript">
        $(document).ready(function () {
            alert("Inscription non-validée. Le maximum d'inscrits est atteint.");
        });
    </script>
}

<h2>Détails</h2>

<fieldset>
    <legend>PROJET</legend>

    <div class="display-label">Titre</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.title)
    </div>

    <div class="display-label">Description</div>
    <div class="display-field-desc">
       @Html.Raw(HttpUtility.HtmlDecode(Model.description))
    </div>

    <div class="display-label">Nb max étudiants</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.max_students)
        @if(!prof){
            @: (@Model.GPI_STUDENT.Count() inscrits)
        }
    </div>

    @{
        if (prof)
        {
            <div class="display-label">Etudiants</div>
            <div class="display-field">
            <ul>
             @{
                foreach (GPI.Models.GPI_STUDENT student in Model.GPI_STUDENT)
                {
                    <li>@student.first_name @student.last_name</li>
                }
             }
             </ul>
             </div>
        }
    }

    <div class="display-label">Année</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.YEAR)
    </div>

    <div class="display-label">Client</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.GPI_PROF1.last_name)
    </div>
    
    @{
        if (prof)
        {
            <div class="display-label">Prof.</div>
            <div class="display-field">
                @Html.DisplayFor(model => model.GPI_PROF.last_name)
            </div>
        }
    }

    @{
        if (prof)
        {
            <div class="display-label">Technologies</div>
            <div class="display-field">
                @{
            Boolean isFirst = true;

            foreach (GPI.Models.GPI_TECHNOLOGY tech in Model.GPI_TECHNOLOGY)
            {
                if (isFirst) { isFirst = false; }
                else
                { @Html.Raw(", ");
                }
                            @tech.name
            }
         }
            </div>
        }
    }
    
    @{
        if (prof || subscribed)
        {
            <div class="display-label">Documents</div>
            <div class="display-field">
                @{
            foreach (GPI.Models.GPI_DOCUMENT doc in Model.GPI_DOCUMENT)
            {
                        @Html.ActionLink(doc.name, "Download", new { id = doc.PK_Document })
                        <br />
            }
                }
            </div>
        }

        if (subscribed && !open)
        {
            Html.BeginForm("Upload", "Project", new { id = Model.PK_Project }, FormMethod.Post, new { enctype = "multipart/form-data" });
            <input type="file" name="file" />
            <input type="submit" value="Upload" />@:(les fichiers de mêmes noms seront écrasés)
            Html.EndForm();
        }
        if (open && !prof)
        {
            <div class="display-label">Inscription</div>
            <div class="display-field">
            @{
                if (subscribed)
                {
                    @Html.ActionLink("Se désinscrire", "Unsubscribe");
                }
                else if (Model.GPI_STUDENT.Count() < Model.max_students)
                {
                    if (ViewBag.CrtStudentProjectID != null)
                    {
                        @Html.ActionLink("S'inscrire", "Subscribe", new { id = Model.PK_Project }, new { onclick = "return confirm('Se désinscrire du précédant projet et s\\'inscrire à celui-ci ?')" });
                    }
                    else
                    {
                        @Html.ActionLink("S'inscrire", "Subscribe", new { id = Model.PK_Project });
                    }
                }
            }
            </div>
        }
        
    }
</fieldset>
<p>
    
    @if (!open && prof && creator)
    {
        @Html.ActionLink("Modifier", "Edit", new { id = Model.PK_Project}) @: |
    }
    @Html.ActionLink("Retour à la liste", "Index")
</p>
